package com.cw1.factory.simpleFactory.pizzastore.order;

import com.cw1.factory.simpleFactory.pizzastore.factroy.SimpleFactory;
import com.cw1.factory.simpleFactory.pizzastore.pizza.Pizza;

import java.io.BufferedReader;
import java.io.InputStreamReader;

/**
 * @Author qiuMi
 * @description 披萨 - 订购
 * @Date 2022-09-28 22:33
 **/
public class OrderPizza {
    /******************方式一*****************/
    /**
     * 构造器 - 订购披萨
     */
//    public OrderPizza(){
//        Pizza pizza = null;
//        String orderType; // 订购披萨的类型
//        do {
//            orderType = getType();
//            if (PizzaConstant.GREEK.equals(orderType)){
//                pizza = new GreekPizza();
//                pizza.setName("希腊披萨");
//            }else if (PizzaConstant.CHESS.equals(orderType)){
//                pizza = new ChessPizza();
//                pizza.setName("切丝披萨");
//            }else if (PizzaConstant.PEPPER.equals(orderType)){
//                pizza = new PepperPizza();
//                pizza.setName("胡椒披萨");
//            } else {
//                break;
//            }
//            // 写出pizza制作过程
//            pizza.prepare();
//            pizza.bake();
//            pizza.cut();
//            pizza.box();
//        }while (true);
//    }

    /******************方式二*****************/
    /**
     * 简单工厂模式
     */
    SimpleFactory simpleFactory;

    public OrderPizza(SimpleFactory simpleFactory) {
        setFactory(simpleFactory);
    }

    private void setFactory(SimpleFactory simpleFactory) {
        // 用户输入
        String orderType = "";
        this.simpleFactory = simpleFactory;
        do {
            orderType = getType();
            Pizza pizza = simpleFactory.createPizza(orderType);
            if (pizza != null) {
                // 写出pizza制作过程
                pizza.prepare();
                pizza.bake();
                pizza.cut();
                pizza.box();
            } else {
                System.out.println("制作披萨失败");
            }
        } while (true);
    }


    /**
     * 写个方法 - 获取客户希望订购的披萨
     */
    private String getType() {
        try {
            System.out.println("input pizza 的种类");
            BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
            // 逐行读取披萨的种类
            String orderType = bufferedReader.readLine();
            return orderType;
        } catch (Exception e) {
            e.printStackTrace();
            return "";
        }

    }
}
